package com.tm.aliyunmassage.util;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
public class AliOSSUtil {
    //Endpoint外网访问域名,以上海为例
    private static  String endpoint="oss-cn-shanghai.aliyuncs.com";
    private static  String accessKeyId="LTAI5t5jPNVQ6GeyszyDzmcn";
    //您的accessKeySecret
    private static  String accessKeySecret="IqucrPpZ8OrLbQdVAv6dPiB9zZVEcU";
    //您的Bucket 名称
    private static String bucketName="cjr2003";
    public static void uploadFile(String fileName,String saveFileName)throws FileNotFoundException{
        //创建OSSClient实例
        OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
       //上传文件流
         InputStream inputStream = new FileInputStream(fileName);
         ossClient.putObject(bucketName,saveFileName,inputStream);
       //关闭OSSClient
        ossClient.shutdown();
    }

    public static void main(String[] args) throws FileNotFoundException {
        uploadFile("D:\\Fialshell-命令图片\\1.png","app/1.png");
    }

}

